package com.bdsy.business.controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.service.OrderService;
import com.bdsy.business.service.ShopSellInfoService;
import com.bdsy.common.annotation.Json;
import com.bdsy.system.annotation.SysLog;

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class ShopManagerController {

	@Autowired
	ShopSellInfoService shopSellInfoService;
	
	@Autowired
	OrderService orderService;
	
	/**
	 * 数量统计
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "countStatis")
	public Object countStatis(String userId){
		Map<String,Object> map = new LinkedHashMap<>();
		//在售物品数量统计 
        int sellCount= shopSellInfoService.sellCount(userId);
        //已完成订单 
        int acount = orderService.acount(userId);
        //未完成订单
        int ncount = orderService.ncount(userId);
        //销量统计 暂时为空
		map.put("code", 200);
		map.put("msg","success");
		map.put("sellCount",sellCount);
		map.put("acount",acount);
		map.put("ncount",ncount);
//		map.put("salesCount", "99");
		return map;
	}
	
	
	/**
	 * 销量统计
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "saleStatis") 
	public Object saleStatis(String userId){
		Map<String,Object> map = new LinkedHashMap<>();
		List name = new ArrayList<>();
		List count = new ArrayList<>();
		List<Map> saleStatis = orderService.saleStatis(userId);
		for (int i = 0; i < saleStatis.size(); i++) {
			name.add(saleStatis.get(i).get("shop_type_name"));
			count.add(saleStatis.get(i).get("count"));
		}
		map.put("code", 200);
		map.put("msg", "success");
		map.put("name", name);
		map.put("count", count);
		return map;
	}
	
	/**
	 * 当前卖家用户所卖商品  已完成订单
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "areadyOrderList")
	public Object areadyOrderList(@RequestParam(value="userId",required=false)String userId,@RequestParam(value="shopTypeId",required=false)int shopTypeId,int lx,int qx){
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> areadyOrderList = orderService.areadyOrderList(userId, shopTypeId, lx, qx);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("areadyOrderList", areadyOrderList);
		return map;
	}
	
	/**
	 * 当前卖家用户所卖商品  未完成订单 
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "nareadyOrderList")
	public Object nareadyOrderList(@RequestParam(value="userId",required=false)String userId,@RequestParam(value="shopTypeId",required=false)int shopTypeId,int orderStatus,int status,int qx){
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> nareadyOrderList = orderService.nareadyOrderList(userId, shopTypeId,orderStatus,status, qx);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("nareadyOrderList", nareadyOrderList);
		return map;
	}
	
} 
